<template>
  <a-card class="a-cardBox" :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="48">
          <a-col
            :md="15"
            :sm="15"
          >
            <a-form-item label="报表时间周期">
              <!-- <a-input
                placeholder="请输入报表时间周期"
                v-model="queryParam.reportTimePeriod"
              /> -->
              <a-range-picker
                @change="onChange"
                v-model="queryParam.reportTimePeriod"
              />
            </a-form-item>
          </a-col>
          <a-col :lg="8" :md="8" :sm="12">
            <a-form-item label="订单数量">
              <a-input
                placeholder="请输入订单数量"
                v-model="queryParam.orderNum"
              />
            </a-form-item>
          </a-col>
          <a-col :lg="8" :md="8" :sm="12">
            <a-form-item label="保费总金额">
              <a-input
                placeholder="请输入保费总金额"
                v-model="queryParam.totalInsurancePremium"
              />
            </a-form-item>
          </a-col>
          <a-col :lg="6" :md="8" :sm="12">
            <span class="table-page-search-submitButtons">
              <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
              <a-button style="margin-left: 8px" @click="() => {$refs.table.refresh(true); queryParam = {}}">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- <div class="table-operator">
      <a-dropdown v-if="removeEnable&&selectedRowKeys.length > 0">
        <a-button type="danger" icon="delete" @click="delByIds(selectedRowKeys)">删除</a-button>
      </a-dropdown>
    </div> -->
    <s-table
      size="default"
      ref="table"
      rowKey="id"
      :columns="columns"
      :data="loadData"
      :scroll="{x:800}"
    >
      <span slot="action" slot-scope="text, record">
        <a v-if="exportEnable" @click="exportExcel([record.id])">下载</a>
      </span>
      <span
        slot="serial"
        slot-scope="text, record, index"
      >
        {{ index + 1 }}
      </span>
      <!-- batchNo -->
      <span
        slot="batchNo"
        slot-scope="text"
      >
        <span v-if="text &&text.length<=10">
          {{ text }}
        </span>
        <span v-else>
          <a-tooltip placement="topLeft">
            <template slot="title">
              <span>{{ text }}</span>
            </template>
            {{ text.substring(0,11) }}...
          </a-tooltip>
        </span>
      </span>
    </s-table>
    <sysInsuranceweekDetails-modal
      ref="modal"
      @ok="handleOk"
    />
  </a-card>
</template>

<script>
import { STable } from '@/components'
import { getSysInsuranceweekDetailsList, delSysInsuranceweekDetails, sysInsuranceweekDetailsExport } from '@/api/system'
import { checkPermission } from '@/utils/permissions'
import { exportExcel } from '@/utils/download'
import moment from 'moment'

export default {
  name: 'TableList',
  components: {
    STable
  },
  data () {
    return {
      labelCol: {
        xs: { span: 5 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 24 }
      },
      form: this.$form.createForm(this),
      mdl: {},
      // 高级搜索 展开/关闭
      advanced: false,
      // 查询参数
      queryParam: {},
      // 表头
      columns: [
        {
          title: '序号',
          width: 80,
          scopedSlots: { customRender: 'serial' }
        },
        {
          title: '报表时间周期',
          width: 230,
          dataIndex: 'reportTimePeriodStart',
          customRender: (value, row, index) => {
            return row.reportTimePeriodStart + '～' + row.reportTimePeriodEnd
          }
        },
        {
          title: '批次号',
          dataIndex: 'batchNo',
          width: 200,
          scopedSlots: { customRender: 'batchNo' }
        },
        {
          title: '订单数量',
          width: 100,
          dataIndex: 'orderNum'
        },
        {
          title: '保费总金额',
          width: 130,
          dataIndex: 'totalInsurancePremium'
        },
        {
          title: '操作',
          width: 60,
          fixed: 'right',
          dataIndex: 'action',
          scopedSlots: { customRender: 'action' }
        }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        console.log('this.queryParam====', this.queryParam)
        const { reportTimePeriod, orderNum, totalInsurancePremium } = this.queryParam
        const params = {}
        if (reportTimePeriod && reportTimePeriod.length) {
          params.reportTimePeriodStart = moment(reportTimePeriod[0]).format('YYYY-MM-DD')
          params.reportTimePeriodEnd = moment(reportTimePeriod[1]).format('YYYY-MM-DD')
        }
        params.orderNum = orderNum
        params.totalInsurancePremium = totalInsurancePremium
        return getSysInsuranceweekDetailsList(Object.assign(parameter, params))
      },
      selectedRowKeys: [],
      selectedRows: [],
      addEnable: checkPermission('system:sysInsuranceweekDetails:add'),
      editEnabel: checkPermission('system:sysInsuranceweekDetails:edit'),
      removeEnable: checkPermission('system:sysInsuranceweekDetails:remove'),
      exportEnable: checkPermission('system:sysInsuranceweekDetails:export')
    }
  },
  filters: {
  },
  created () {
  },
  methods: {
    onSelectChange (selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
    },
    handleAdd () {
      this.$refs.modal.add()
    },
    handleEdit (record) {
      this.$refs.modal.edit(record)
    },
    handleOk () {
      this.$refs.table.refresh(true)
      console.log('handleSaveOk')
    },
    delByIds (ids) {
      delSysInsuranceweekDetails({ ids: ids.join(',') }).then(res => {
        if (res.code === 0) {
          this.$message.success('删除成功')
          this.handleOk()
        } else {
          this.$message.error(res.msg)
        }
        this.selectedRowKeys = []
      })
    },
    exportExcel (ids) {
      exportExcel(sysInsuranceweekDetailsExport, { ids: ids.join(',') })
    }
  },
  watch: {
    /*
      'selectedRows': function (selectedRows) {
        this.needTotalList = this.needTotalList.map(item => {
          return {
            ...item,
            total: selectedRows.reduce( (sum, val) => {
              return sum + val[item.dataIndex]
            }, 0)
          }
        })
      }
      */
  }
}
</script>
<style lang="less" scope>
.a-cardBox{
 width: 100%;
 height:  e("calc(100vh - 203px)");
 background: #fff;
}
</style>
